﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using System.Collections;
using System.Configuration;


namespace EHR18
{
    public partial class FrmIOTrace :BaseChild
    {

        I_IO_Card iocard = IOFactory.getIO_Instance(GenneralConfig.instance.IO_TYPE);
        ArrayList arr = new ArrayList();
        public FrmIOTrace()
        {
            InitializeComponent();
        }
        public static  FrmIOTrace instance ;

        public static FrmIOTrace GetInstance()
        {
            if(instance!=null&&instance.IsDisposed==false)
            {
               
            }
            else
            {
                instance = new FrmIOTrace();
            }
            return instance;
        }
        private void IOTrace(ushort value)
        {
            if (InvokeRequired)
            {
                Invoke(new Action<ushort>(IOTrace), value);
                return;
            }
            this.textBox1.Text = value.ToString("") + Environment.NewLine;
        }

       
        private void timer1_Tick(object sender, EventArgs e)
        {
            uint DIVal = iocard.Read();
            arr = ControlArrayUtils.getControlArray(this, "pbout", "");
            for (int index = 0; index < 16; index++)
            {

                if ((DIVal & (1 << (index))) == 0)
                {
                    ((PictureBox)arr[index]).BackColor = Color.Gray;
                }
                else
                {
                    ((PictureBox)arr[index]).BackColor = Color.Red;
                }
            }
        }

     

        private void FrmIOTrace_Load_1(object sender, EventArgs e)
        {
            arr = ControlArrayUtils.getControlArray(this, "lbtip", "");
            List<TestItem> testItems = GenneralConfig.instance.module.TestItems;
            if (testItems != null)
            {
                foreach (var item in testItems.Where(t => t.IsUse == true))
                {
                    ((Label)arr[item.Location]).Text = item.Name.Trim('"').Contains("耐压") ? item.Name.Trim('"') + "结果" : item.Name.Trim('"') + "测试完成";
                }
                int io_alltestok = GenneralConfig.instance.module.DI_TEST_OVER;
                ((Label)arr[io_alltestok]).Text = "所有测试完成";
                int io_stop = GenneralConfig.instance.module.DI_FINNISH_MODE;
                ((Label)arr[io_stop]).Text = "结束模式";

            }
            iocard.TrigEvent += IOTrace;
            Font = new Font("宋体", 9);
        }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

    }

}
